<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!-- <p>股票价格：<span></span></p>
    <button>更新</button> -->

    <!DOCTYPE html>
    <html lang="en">

    <head>
        <meta charset="UTF-8">
        <title>日期时间选择器</title>
    </head>

    <body>
        <label for="year">年:</label>
        <select id="year"></select>

        <label for="month">月:</label>
        <select id="month"></select>

        <label for="day">日:</label>
        <select id="day"></select>

        <label for="hour">时:</label>
        <select id="hour"></select>

        <label for="minute">分:</label>
        <select id="minute"></select>

        <label for="second">秒:</label>
        <select id="second"></select>

        <script src="datetime-selector.js"></script>
    </body>

    </html>
    <script>
        function populateSelect(elementId, values) {
            const select = document.getElementById(elementId);
            values.forEach(value => {
                const option = document.createElement('option');
                option.value = value;
                option.textContent = value;
                select.appendChild(option);
            });
        }

        // 填充年份下拉框，例如从当前年份到当前年份+5年
        const currentYear = new Date().getFullYear();
        populateSelect('year', Array.from({ length: 6 }, (_, i) => currentYear + i));

        // 填充月份下拉框
        populateSelect('month', Array.from({ length: 12 }, (_, i) => i + 1));

        // 填充日期下拉框，以当前月份为例，这里简化为31天
        populateSelect('day', Array.from({ length: 31 }, (_, i) => i + 1));

        // 填充小时、分钟、秒下拉框
        ['hour', 'minute', 'second'].forEach(unit => {
            populateSelect(unit, Array.from({ length: 60 }, (_, i) => (i < 10 ? '0' + i : i)));
        });
        // //假设这是获取股票的价格函数
        // function gupiao() {
        //     document.querySelector('span').innerText = Math.floor(Math.random() * 1000)
        //     console.log('股票价格已更新');
        // }

        // //设置定时器，每60秒更新一次股票价格
        // const stock = setInterval(gupiao, 1000)

        // //当用户关闭关闭股票价格更新功能时，清除定时器
        // document.querySelector('button').addEventListener('click', () => {
        //     clearInterval(stock)
        //     console.log('股票价格更新已停止');

        // })
    </script>
</body>

</html>